package com.allwees.bs.module.mms.wf;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.allwees.core.wf.FsmState;
import com.allwees.core.wf.Transition;

import java.util.Arrays;
import java.util.List;

/**
 * 供应商入驻流程状态机
 *
 * @author yangylsky
 * @since 2019-12-03
 *
 */
public enum ESupplierApplyState implements FsmState<ESupplierApplyState, ESupplierApplyAction>, IEnum<String> {
	START("Start", false, false) {
		@Override
		public List<Transition<ESupplierApplyState, ESupplierApplyAction>> getTransitions() {
			return Arrays.asList(
				new Transition<>(ESupplierApplyAction.SUPPLIER_COMMIT, WAIT_AUDIT)
			);
		}
	},

	WAIT_AUDIT("提交资料",true, false) {
		@Override
		public List<Transition<ESupplierApplyState, ESupplierApplyAction>> getTransitions() {
			return Arrays.asList(
				new Transition<>(ESupplierApplyAction.PLATFORM_FIRST_REJECTED, MODIFY),
				new Transition<>(ESupplierApplyAction.PLATFORM_FIRST_APPROVED, WAIT_FINAL_AUDIT)
			);
		}
	},

	MODIFY("未审批通过", true, false) {
		@Override
		public List<Transition<ESupplierApplyState, ESupplierApplyAction>> getTransitions() {
			return Arrays.asList(
				new Transition<>(ESupplierApplyAction.SUPPLIER_COMMIT, WAIT_AUDIT),
				new Transition<>(ESupplierApplyAction.SUPPLIER_CANCEL, CANCELED)
			);
		}
	},

	WAIT_FINAL_AUDIT("待终审", true, false) {
		@Override
		public List<Transition<ESupplierApplyState, ESupplierApplyAction>> getTransitions() {
			return Arrays.asList(
					new Transition<>(ESupplierApplyAction.PLATFORM_FINAL_REJECTED, MODIFY),
					new Transition<>(ESupplierApplyAction.PLATFORM_FINAL_APPROVED, COMPLETED)
			);
		}
	},

	CANCELED("Canceled", false, true),

	COMPLETED("已审批通过", false, true);

	/**
	 * 状态描述
	 */
	private String desc;

	private boolean started;

	private boolean ended;

	/**
	 * 数据库存储用值
	 */
	public String key() {
		return name();
	}

	public String desc() {
		return desc;
	}

	@Override
	public boolean started() {
		return started;
	}

	@Override
	public boolean ended() {
		return ended;
	}

	ESupplierApplyState(String desc, boolean started, boolean ended) {
		this.desc = desc;
		this.started = started;
		this.ended = ended;
	}

	@Override
	public String getValue() {
		return name();
	}
}
